<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
	  <%@include file="/res/include/base-head.jsp"%>
	  <%@include file="/res/include/jquery-easyui.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath}/res/js/mall/product.js"></script>
  </head>
  <body>
<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'north',border:false,split:false" style="overflow:hidden">        
        <form id="queryProduct-form" class="search_form clearfix">
        	<dl>
            	<dt>商品名称：</dt>
                <dd><input name="name" type="text" class="txt grid-12" maxlength="16"/></dd>
            </dl>

   
            <p class="search_form_btn"><input type="button" value="搜索" class="icon_serach" onclick="queryProduct()" /><span>(双击商品数据行，即可完成添加操作)</span></p>

        </form>
    </div>    
	<div data-options="region:'center',border:false">
  		<table id="datagridProduct" data-options="url:'${pageContext.request.contextPath}/mall/product/list?shopId=1'">
			<thead>
				<tr>
				    <th data-options="field:'id',align:'center',width:50">商品ID</th>
					<th data-options="field:'name',align:'center',width:250">商品名称</th>
					<th data-options="field:'status',width:80,align:'center',formatter:formatStatus">状态</th>
				</tr>
			</thead>
		</table>
    </div>    
</div>
<script type="text/javascript">
	function formatStatus(value,row,index) {
		var l_html = '上架';
		if (value==2) {
			l_html = '下架';
		} else if (value==3) {
			l_html = '失效';
		}
		return l_html;
	}
	
	function queryProduct() {
		if (!$('#queryProduct-form').form('validate'))
			return;
		var data = $('#queryProduct-form').form('jsonObject');
		$('#datagridProduct').datagrid('load', data);
	}
	
	easyui.util.initDatagrid('#datagridProduct',{
		onDblClickRow:function() {
			var param = {};
			var url = contextPath+'/mall/subject/product/add';
			var row = $('#datagridProduct').datagrid('getSelected');
			param.productId = row.id;
			param.subjectId = '${subjectId}';
			//alert(JSON.stringify(row));
			$.post(url,param,function(result) {
				if(result.code==1) {
					top.showInfo('添加成功');
				} else {
					top.showInfo('添加失败:'+result.msg);
				}
			},'json'); 				
			//$('#query-dialog').dialog('close'); 
		}
	});
</script>
  </body>
</html>